#include <string>
#include <algorithm>
using namespace std;
class Solution {
public:
    string addBinary(string a, string b) {
        reverse(a.begin(), a.end());
		reverse(b.begin(), b.end());
		string ret;
		int t=0;
		int length = min(a.size(), b.size());
		for(int i=0;i<length;++i)
		{
			t = t + a[i] + b[i]-'0'-'0';
			ret.push_back(t % 2 + '0');
			t /= 2;
		}
		for(int i=length;i<a.size();++i)
		{
			t = t + a[i]-'0';
			ret.push_back(t % 2 + '0');
			t /= 2;
		}
		for(int i=length;i<b.size();++i)
		{
			t = t + b[i]-'0';
			ret.push_back(t % 2 + '0');
			t /= 2;
		}
		if (t != 0)
			ret.push_back(t + '0');
		reverse(ret.begin(), ret.end());
		return ret;
    }
};
int main()
{
	Solution().addBinary("111", "333");
}